//Accepdet
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
 
using namespace std;
typedef unsigned long long ll;

char a[20];
char b[20], c;
int n, i, j, k, p;
bool maior(){//b>=a
	for(k=0;k<n;k++){
		if(a[k]>b[k])return false;
		else if(a[k]<b[k])return true;
	}
	return true;
}
void shift(){
	for(k=n;k>0;k--)a[k]=a[k-1];
	a[0]='0';
	n++;
}
void read(){
	scanf("%s", a);
}
void process(){
	n = strlen(a);
	if(n%2)shift();
	p=n/2;
	for(i=0;i<p;i++){
		b[i]='4';
		b[i+p]='7';
	}
	for(i=p-1;i>=0;i--){
		for(j=i+1;j<=i+p;j++){
			if(maior())return;
			//cout<<i<<""<<j<<" "<<a<<" "<<b<<endl;
			c= b[j-1];
			b[j-1] = b[j];
			b[j] = c;
		}
	}
	if(maior())return;
	
	p++;
	for(i=0;i<p;i++){
		b[i]='4';
		b[i+p]='7';
	}
}
int main(){
	//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
	read();
	process();
	cout<< b;
	return 0;
}
